var AOJ_KEY_UP = 0;
var AOJ_KEY_DOWN = 1;
var AOJ_KEY_LEFT = 2;
var AOJ_KEY_RIGHT = 3;
var AOJ_KEY_ACTION = 4;
var AOJ_MOUSE = 5;
var _aojKeys = new Array();
for (var k=0; k<=5; k++) {
    _aojKeys[k] = false;
}
var _aojMousePos = {
    x:0,
    y:0
};

function aojInitInput() {

}

function aojIsPressed(key)
{
    return _aojKeys[key];
}

function aojIsReleased(key)
{
    return !_aojKeys[key];
}

function aojMouseX() {
    return _aojMousePos.x;
}

function aojMouseY() {
    return _aojMousePos.y;
}

document.onkeydown = function(event) {
    var keyCode;

    if(event == null)
    {
        keyCode = window.event.keyCode;
    }
    else
    {
        keyCode = event.keyCode;
    }

    switch(keyCode)
    {
        case 37:
            _aojKeys[AOJ_KEY_LEFT] = true;
            break;
        case 38:
            _aojKeys[AOJ_KEY_UP] = true;
            break;
        case 39:
            _aojKeys[AOJ_KEY_RIGHT] = true;
            break;
        case 40:
            _aojKeys[AOJ_KEY_DOWN] = true;
            break;
        case 32:
            _aojKeys[AOJ_KEY_ACTION] = true;
            break;
    }
}
document.onkeyup = function(event) {
    var keyCode;

    if(event == null)
    {
        keyCode = window.event.keyCode;
    }
    else
    {
        keyCode = event.keyCode;
    }

    switch(keyCode)
    {
        case 37:
            _aojKeys[AOJ_KEY_LEFT] = false;
            break;
        case 38:
            _aojKeys[AOJ_KEY_UP] = false;
            break;
        case 39:
            _aojKeys[AOJ_KEY_RIGHT] = false;
            break;
        case 40:
            _aojKeys[AOJ_KEY_DOWN] = false;
            break;
        case 32:
            _aojKeys[AOJ_KEY_ACTION] = false;
            break;
    }
}

document.onmousemove = function(event)
{
    if (event.pageX || event.pageY)
    {
        _aojMousePos.x = event.pageX;
        _aojMousePos.y = event.pageY;
    }
    else if (event.layerX || event.layerX)
    {
        _aojMousePos.x = event.layerX;
        _aojMousePos.y = event.layerY;
    } else if (event.offsetX || event.offsetX)
{
        _aojMousePos.x = event.offsetX;
        _aojMousePos.y = event.offsetY;
    }
    else {
        _aojMousePos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        _aojMousePos.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
}

document.onmousedown = function(event)
{
    _aojKeys[AOJ_MOUSE] = true;
}

document.onmouseup = function(event)
{
    _aojKeys[AOJ_MOUSE] = false;
}